package com.innovate.nms.view;

import com.innovate.nms.domain.UdpConfig;
import com.ivan.toolkit.swing.ConfigDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import com.ivan.toolkit.swing.PromptTextField;

public class WiredConfigDialog extends ConfigDialog {



	/**
	 * 
	 */
	private static final long serialVersionUID = 8952529801405625601L;
	private PromptTextField tfListenPort;
	private PromptTextField tfTimeout;

	/**
	 * Create the dialog.
	 */
	public WiredConfigDialog() {
		setTitle("有线通道配置");
		setBounds(100, 100, 547, 487);
		
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel label = new JLabel("监听端口（默认：7373）：");
		label.setBounds(41, 61, 229, 18);
		panel.add(label);
		
		tfListenPort = new PromptTextField();
		tfListenPort.setBounds(42, 96, 199, 24);
		panel.add(tfListenPort);
		
		JLabel label_1 = new JLabel("超时时间（单位：毫秒）：");
		label_1.setBounds(42, 150, 229, 18);
		panel.add(label_1);
		
		tfTimeout = new PromptTextField();
		tfTimeout.setBounds(42, 181, 199, 24);
		panel.add(tfTimeout);
	}

	@Override
	protected void prepare() throws Exception {
		UdpConfig config = UdpConfig.instance.get();
		tfListenPort.setText(Integer.toString(config.getListenPort()));
		tfTimeout.setText(Integer.toString(config.getTimeout()));
	}

	@Override
	protected void doCommit() throws Exception {
		
		int port = this.toInteger(tfListenPort, "无效的监听端口");
		
		int timeout = this.toInteger(tfTimeout, "无效的超时时间");
		
		UdpConfig config = UdpConfig.instance.get();
		config.setListenPort(port);
		config.setTimeout(timeout);
		UdpConfig.instance.set();
	}
	
	
}
